#pragma once

// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license


#include "Ref.h"
#include "Pickable.h"
class View3d;
class AABB;

BEGIN_ENUM(GeometrySide)
    Front=GL_FRONT, Back=GL_BACK, Both=GL_FRONT_AND_BACK
END_ENUM(GeometrySide)



class Geometry : public Pickable
{
public:

    Geometry()
    : m_requiredTexCoords(1), m_flipNormals(false)
    {
    }

    virtual void draw(View3d* view) const = 0;
    virtual AABB getAABB() const = 0;
    virtual ref<Geometry> clone() const = 0;
    virtual bool supportsTexturing() const { return false; }
    
    void setRequiredTextureCoords(size_t num) { m_requiredTexCoords = num; }
    size_t getRequiredTexCoords() const { return m_requiredTexCoords; }

    void setFlipNormals(bool v=true) { m_flipNormals = v; }

private:

    // Only the GeometryFactory can read/write
    friend class GeometryFactory;
    friend class PrimitiveFactory;
    void write(std::wostream& os) const { writeImpl(os); }
    void read(std::wistream& is) { readImpl(is); }

protected:

    size_t m_requiredTexCoords;
    bool m_flipNormals;

    // Give a chance to derived class to R/W their stuff
    virtual void writeImpl(std::wostream&) const {}
    virtual void readImpl(std::wistream&) {}
};

